package com.zhy.http.okhttp;

import com.zhy.http.library.OkHttpUtils;
import com.zhy.http.library.cookie.CookieJarImpl;
import com.zhy.http.library.cookie.store.MemoryCookieStore;
import com.zhy.http.library.https.HttpsUtils;
import com.zhy.http.library.log.LoggerInterceptor;

import ohos.aafwk.ability.AbilityPackage;
import okhttp3.OkHttpClient;

import java.util.concurrent.TimeUnit;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;

public class MyHapPackage extends AbilityPackage {
    @Override
    public void onInitialize() {
        super.onInitialize();

        HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null, null, null);

        CookieJarImpl cookieJar1 = new CookieJarImpl(new MemoryCookieStore());
        OkHttpClient okHttpClient =
                new OkHttpClient.Builder()
                        .connectTimeout(10000L, TimeUnit.MILLISECONDS)
                        .readTimeout(10000L, TimeUnit.MILLISECONDS)
                        .addInterceptor(new LoggerInterceptor("Sample"))
                        .cookieJar(cookieJar1)
                        .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
                        .build();

        OkHttpUtils.initClient(okHttpClient);
    }
}
